## Constructs Table 1 from Appendix C

# Import packages
import pandas as pd
import matplotlib.pyplot as plt
from matplotlib.font_manager import FontProperties

# File locations; change as needed
hearing_data_location = "D:/Dropbox/congressworks/drafts/measurement paper/measurement_replication/topics/manual_hearing_topics.csv"

# Read in selected hearings data
selected_hearings = pd.read_csv(hearing_data_location)
grouped_selected_hearings = selected_hearings.groupby(by = "topic").size()
grouped_selected_hearings = grouped_selected_hearings.sort_values(ascending = False)
grouped_selected_hearings["Total"] = grouped_selected_hearings.sum()

# Convert series into df for easier plotting
grouped_selected_hearings_df = pd.DataFrame({'Topic':grouped_selected_hearings.index, 'Count':grouped_selected_hearings.values})

# Plot data as a matplotlib table
fig, ax = plt.subplots()
# Hide axes
fig.patch.set_visible(False)
ax.axis('off')
ax.axis('tight')
table = ax.table(cellText = grouped_selected_hearings_df.values,
         colLabels = grouped_selected_hearings_df.columns,
         loc = 'center',
         cellLoc = 'left')

# Customization
table[(0, 0)].set_facecolor("gray")
table[(0, 0)].set_text_props(fontproperties=FontProperties(weight='bold'))
table[(0, 1)].set_facecolor("gray")
table[(0, 1)].set_text_props(fontproperties=FontProperties(weight='bold'))
table[(17, 0)].set_facecolor("gray")
table[(17, 0)].set_text_props(fontproperties=FontProperties(weight='bold'))
table[(17, 1)].set_facecolor("gray")
table[(17, 1)].set_text_props(fontproperties=FontProperties(weight='bold'))

plt.show()